package com.cn.txx.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.cn.txx.dao.zydao.DCityMapper;
import com.cn.txx.entity.DCity;
import com.cn.txx.entity.UserCity;
import com.cn.txx.service.WelcomeService;
import com.cn.txx.utils.Constants;
import com.cn.txx.utils.RedisUtils;

@Service
public class WelcomeServiceImp implements WelcomeService{

	private Logger logger = Logger.getLogger(this.getClass());
	@Autowired
	private RedisUtils redisUtils;
	@Autowired
	private DCityMapper dcityMapper;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<DCity> loadCityByPro() {
		List<DCity> list = null;
		try {
			Object obj = redisUtils.get(Constants.CITY_PRO);
			if(!StringUtils.isEmpty(obj)){
				logger.debug("从redis中获取省缓存");
				return (List<DCity>)obj;
			}
		   list = dcityMapper.selectAllCityByPro();
		   redisUtils.set(Constants.CITY_PRO, list);
		} catch (Exception e) {
			logger.error("loadCityByPro erro...",e);
		}
		return list;
	}

	@Override
	public List<UserCity> loadCityByUser(String uid) {
		List<UserCity> list = null;
		try {
		   list = dcityMapper.loadCityByUser(uid);
		} catch (Exception e) {
			logger.error("loadCityByPro erro...",e);
		}
		return list;
	}

}
